package fr.inserm.um915.bdibd.model;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Writer;
import java.util.zip.GZIPInputStream;

public class IOUtils
	{
	public static BufferedReader open(File f) throws IOException
		{
		if(f.getName().endsWith(".gz"))
			{
			return new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(f))));
			}
		return new BufferedReader(new FileReader(f));
		}
	
	public static void safeClose(Writer out)
		{
		if(out==null) return;
		try {
			out.close();
			} 
		catch (Exception e)
			{
			}
		}
	
	public static void safeClose(Reader in)
		{
		if(in==null) return;
		try {
			in.close();
			} 
		catch (Exception e)
			{
			}
		}
	public static void safeClose(InputStream in)
		{
		if(in==null) return;
		try {
			in.close();
			} 
		catch (Exception e)
			{
			}
		}
	}
